package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Collections;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try ( Connection con = DBUtil.getConnection()){
            Statement sta = con.createStatement();
            String sql = "SELECT t.name,t.gender,c.name,c.floor " +
                    "FROM teacher t ,class c "+
                    "WHERE t.id = c.teacher_id "+
                    "AND t.name='王克晶'";
            ResultSet rs = sta.executeQuery(sql);
            while (rs.next()){
                String name = rs.getString("t.name");
                String gender = rs.getString("t.gender");
                String className = rs.getString("c.name");
                int floor = rs.getInt("c.floor");
                System.out.println(name+" "+gender+" "+className+" "+floor);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
